package com.net.tkc.pro.tool;

import com.net.tkc.pro.tool.BaiDu.OCR.HttpUtil;
import net.sf.json.JSONObject;
//import org.json.JSONObject;

public class API2Tool {
    public static final String KEY = "12870b733a30868d94748e6e2fe64e0b";// 你的appkey
    public static final String URL = "http://apis.juhe.cn/qrcode/api";
    public static final String text = "反诈码，是方便用户用于展示自己的反诈意识，" +
            "";
    public static final String bgcolor = "FFFFFF";
    public static final String fgcolor = "00FF00";
//    public static final int type=2;
    public static String Get() {
        String qrcode="";
        String result = null;
        String url = URL + "?key=" + KEY +"&bgcolor"+bgcolor+"&fgcolor"+fgcolor
        + "&text=" + text;
        try {
            result = HttpUtil.sendGet(url, "utf-8");
            JSONObject json = JSONObject.fromObject(result);
            if (json.getInt("error_code")!= 0) {
                qrcode =json.getString("reason");
            } else {
                JSONObject resultarr = json.optJSONObject("result");
                qrcode = resultarr.getString("base64_image");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return qrcode;
    }
}

